/*
 * FOF新建模块
 */
require('!style!css!../css/create.css');
var createHtml = require('!html!../html/create.html');
var common = require('./common.js');
var config = require('./config.js');
var page = require('./page.js');
var createVue;
var create = {
    init: function () {
        page.setPage(2);
        common.initNav(1);
        $('.step').hide();
        $('#create').html(createHtml).show();
        this.initRiskData();
        this.initCallback();
        common.getData({
            path: 'fofTypeList',
            callback: 'showFofTypeList'
        });
    },
    initRiskData: function () {
        var risk = [8, 5, 2];
        var riskDefaultIndex = 1;
        $('.risk-select input').eq(riskDefaultIndex).attr('checked', true).val();
        $('.profit-calculate input').val(risk[riskDefaultIndex]);
        $('.risk-select input').each(function (i) {
            $(this).val(risk[i]);
        });
        $('.risk-select input').change(function () {
            $('.profit-calculate input').val($(this).val());
        });
    },
    initCallback: function () {
        window['showFofTypeList'] = function (json) {
            var data = common.filterData(json, 'fofTypeList');
            if (data) {
                var rcm = [];
                $.each(data, function (k, v) {
                    $.each(v.list, function (kk, vv) {
                        if (vv.rcm == 1) {
                            rcm.push(vv);
                        }
                    });
                });
                createVue = new Vue({
                    el: '#create',
                    data: {
                        defaultProfitTypeStr: common.staticData.profitType,
                        defaultProductTypeStr: common.staticData.productType,
                        profitTypeList: data,
                        productTypeList: [],
                        rcmList: rcm
                    },
                    methods: {
                        changeProfitType: function () {
                            var val = $('#profitType').val();
                            $.each(createVue.profitTypeList, function (k, v) {
                                if (v.id == val) {
                                    createVue.productTypeList = v.list;
                                    return false;
                                }
                            });
                        },
                        next: function () {
                            create.next();
                        }
                    }
                });
            }
        };
    },
    next: function () {
        console.log('next click...');
        var productTypeId = $('input:radio[name="FOFStyle"]:checked').val();
        if (productTypeId == null) {
            productTypeId = $('#productType').val();
        }
        if (!productTypeId) {
            alert('请选择已有类型/定制类型');
            return false;
        }
        var risk = $('.profit-calculate input').val();
        if (!risk) {
            alert('请输入年化波动率 / 跟踪误差');
            return false;
        }
        var fund = $('input:radio[name="fund"]:checked').val();
        var configOption = {
            productTypeId: productTypeId,
            risk: risk,
            fund: fund
        };
        window['configOption'] = configOption;
        config.init(configOption);
    }
};
for (var key in create) {
    if (key) {
        exports[key] = create[key];
    }
}